package com.mofum.cloud.core.model;

import com.mofum.cloud.core.error.device.memory.MemoryReadException;
import com.mofum.cloud.core.error.device.memory.MemoryWriteException;

import java.math.BigInteger;

/**
 * 内存
 * ===================================================================
 * <p> 内存设备
 * ===================================================================
 *
 * @author yumi@omuao.com
 */
public interface Memory extends Device {
    /**
     * 可读区间左值
     */
    String READ_SECTION_LEFT = "READ_SECTION_LEFT";
    /**
     * 可读区间右值
     */
    String READ_SECTION_RIGHT = "READ_SECTION_RIGHT";

    /**
     * 可写区间左值
     */
    String WRITE_SECTION_LEFT = "WRITE_SECTION_LEFT";
    /**
     * 可写区间右值
     */
    String WRITE_SECTION_RIGHT = "WRITE_SECTION_RIGHT";

    /**
     * 未定义
     */
    BigInteger UNDEFINED = new BigInteger("-1");

    /**
     * 定义内存设备
     *
     * @return 内存设备
     */
    @Override
    default DeviceType getDeviceType() {
        return DeviceType.MEMORY;
    }

    /**
     * 读取内存
     *
     * @param address 内存地址
     * @return 值
     * @throws MemoryReadException 内存读取异常
     */
    BigInteger read(BigInteger address) throws MemoryReadException;

    /**
     * 写内存
     *
     * @param address 地址
     * @param value   值
     * @throws MemoryWriteException 内存写入异常
     */
    void write(BigInteger address, BigInteger value) throws MemoryWriteException;

    /**
     * 读取内存
     *
     * @param address 内存地址
     * @return 值
     * @throws MemoryReadException 内存读取异常
     */
    BigInteger load(BigInteger address) throws MemoryReadException;

    /**
     * 写内存
     *
     * @param address 地址
     * @param value   值
     * @throws MemoryWriteException 内存写入异常
     */
    BigInteger store(BigInteger address, BigInteger value) throws MemoryWriteException;

    /**
     * 读取内存
     *
     * @param address 内存地址
     * @return 值
     * @throws MemoryReadException 内存读取异常
     */
    BigInteger get(BigInteger address) throws MemoryReadException;

    /**
     * 写内存
     *
     * @param address 地址
     * @param value   值
     * @throws MemoryWriteException 内存写入异常
     */
    BigInteger set(BigInteger address, BigInteger value) throws MemoryWriteException;

}
